package com.zhou.test.thymeleaf.controller;


import com.zhou.test.thymeleaf.model.Blog;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xianfeng
 * @date 2023/5/12 20:36
 */
@Controller
public class MyController {

    @RequestMapping("/test")
    public String test1(Model model) {
        model.addAttribute("msg", "user.password.retry.limit.count");
        return "test";
    }

    @RequestMapping("/test2")
    public String test2(Model model) {
        model.addAttribute("msg", "标准变量表达式");
        Blog blog = new Blog();
        blog.setId(1);
        blog.setName("yixin");
        blog.setPwd("123");
        model.addAttribute("blog", blog);
        return "test2";
    }

    @RequestMapping("/test3")
    public String test3(Model model) {
        model.addAttribute("msg", "标准变量表达式");
        Blog blog = new Blog();
        blog.setId(1);
        blog.setName("yixin");
        blog.setPwd("123");
        model.addAttribute("blog", blog);
        return "test3";
    }

    @RequestMapping("/test4")
    public String test4(Model model) {
        return "test4";
    }

    @RequestMapping("/blog")
    @ResponseBody
    public String getUserById(Integer id) {
        System.out.println("id=" + id);
        return "id=" + id;
    }

    @RequestMapping("/blogList")
    public String hello(Model model) {
        List<Blog> blogList = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            Blog blog = new Blog();
            blog.setId(i);
            blog.setPwd("abcd" + i);
            blog.setName("一心" + i);
            blogList.add(blog);
        }
        model.addAttribute("blogList", blogList);
        return "test5";
    }

    @RequestMapping("/login")
    public String index2(Model model) {
        return "login";
    }

}
